//
//  MyViewController.m
//  TouTiao
//
//  Created by 柴旭 on 16/9/12.
//  Copyright © 2016年 Match. All rights reserved.
//

#import "MyViewController.h"

#define IMGH 200

@interface MyViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (strong, nonatomic) IBOutlet UITableView *tableView;
@property(nonatomic,strong)UIImageView *imageView;

//@property(nonatomic,strong)UIImageView *imageView;
//@property(nonatomic,strong)UIImage *image;

@end

@implementation MyViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self HeadeView];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell_id"];
}

-(void)HeadeView
{
    //    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 200)];
    //    //添加图片
    //    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 200)];
    //    imageView.image = [UIImage imageNamed:@"wallpaper_profile~ipad"];
    //    [view addSubview:imageView];
    //
    //    self.tableView.tableHeaderView = view;
    //    [self.tableView addSubview:view];
    
    self.tableView.contentInset = UIEdgeInsetsMake(IMGH, 0, 0, 0);
    _imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, -IMGH, [UIScreen mainScreen].bounds.size.width, IMGH)];
    _imageView.image = [UIImage imageNamed:@"wallpaper_profile.jpg"];
    
    _imageView.tag = 101;
    
    [self.tableView addSubview:_imageView];
}


//设置拖动事件
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    _imageView.contentMode = UIViewContentModeScaleAspectFill;
    CGPoint point = scrollView.contentOffset;
    if (point.y < -IMGH)
    {
        CGRect rect = [self.tableView viewWithTag:101].frame;
        rect.origin.y = point.y;
        rect.size.height = -point.y;
        [self.tableView viewWithTag:101].frame = rect;
    }
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 30;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell_id" forIndexPath:indexPath];
    cell.textLabel.text = [NSString stringWithFormat:@"%ld--%ld",indexPath.section,indexPath.row];
    return cell;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
